package com.kgc.untils;

public class PageUtils {
    private int currPageNo = 1;        //当前页码
    private int totalPageCount = 0;    //总页数
    private int pageSize = 5;         //每页展示记录数
    private int totalCount;            //记录总条数

    public void init(int total) {
        this.totalCount = total;
        //计算总页数
        this.totalPageCount = this.totalCount % this.pageSize == 0 ?
                this.totalCount / this.pageSize : this.totalCount / this.pageSize + 1;
        if (this.currPageNo < 1) {
            this.currPageNo = 1;
        }
        if (this.currPageNo > this.totalPageCount) {
            this.currPageNo = this.totalPageCount;
        }
    }

    public int start() {
        if (this.currPageNo < 1) {
            this.currPageNo = 1;
        }
        return (this.currPageNo - 1) * this.pageSize;
    }

    public int getCurrPageNo() {
        return currPageNo;
    }

    public void setCurrPageNo(int currPageNo) {
        this.currPageNo = currPageNo;
    }

    public int getTotalPageCount() {
        return totalPageCount;
    }

    public void setTotalPageCount(int totalPageCount) {
        this.totalPageCount = totalPageCount;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }
}
